package com.longe.controller;

import com.longe.service.MinioService;
import com.longe.util.FileTypeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 */
@RequestMapping("/minio")
@RestController
public class MinioController {

    @Autowired
    private MinioService minioService;

    @PostMapping("/upload")
    public String uploadFile(MultipartFile file) {
        String fileType = FileTypeUtils.getFileType(file);
        if (fileType != null) {
            return minioService.putObject(file, fileType);
        }
        return "不支持的文件格式。请确认格式,重新上传！！！";
    }

    @DeleteMapping("/removeObject/{objectName}")
    public String delObject(@PathVariable("objectName") String objectName) {
        return minioService.removeObject(objectName) == true ? "删除成功" : "删除失败";
    }
}
